import urllib.request as ur
import urllib.parse as up
import json
import os

content = input('请输入需要翻译的内容（英文）：')
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'

data = {}
data['type'] = 'AUTO'
data['i'] = content
data['doctype'] = 'json'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '1531896840732'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_REALTIME'
data['typoResult'] = 'false'

data = up.urlencode(data).encode('utf-8')
response = ur.urlopen(url, data)
html = response.read().decode('utf-8')
target = json.loads(html)
target1 = target['translateResult'][0][0]['tgt']
print('翻译结果（中文）: %s' % (target1))
os.system('pause')